package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

class zapu {
   zaqd a;
   zaps b;
   zaqd c;
   zaps d;
   ArrayList e;
   ArrayList f;
   HashMap g;
   HashMap h;
   Worksheet i;
   Cells j;
   zapt k;
   String l;
   String m;
   ArrayList n;
   boolean o;
   boolean p;
   ArrayList[] q;
   ArrayList[] r;
   ArrayList[] s;
   ArrayList[] t;
   ArrayList u;

   zapu(zapt var1, Worksheet var2) {
      this.k = var1;
      this.i = var2;
      this.l = this.a(var2.getName());
      this.j = var2.getCells();
      this.g = new HashMap();
      this.h = new HashMap();
      this.a = new zaqd(this.j, var1.d.size() + 1);
      com.aspose.cells.b.a.a.ze.a(var1.d, (Object)this.a);
      this.a.a("ro" + this.k.d.size());
      this.b = new zaps(this.j, var1.c.size() + 1);
      com.aspose.cells.b.a.a.ze.a(var1.c, (Object)this.b);
      this.b.a("co" + var1.c.size());
      this.m = "false";
      var2.b(this.l);
   }

   private String a(String var1) {
      char[] var2 = var1.toCharArray();
      int var3 = 0;

      while(var3 < var2.length) {
         switch(var3) {
         case 33:
         case 34:
         case 35:
         case 36:
         case 37:
         case 38:
         case 39:
         case 40:
         case 41:
         case 42:
         case 43:
         case 44:
         case 45:
         case 46:
         case 47:
         case 58:
         case 59:
         case 60:
         case 61:
         case 62:
         case 63:
         case 64:
         case 91:
         case 92:
         case 93:
         case 94:
         case 96:
         case 123:
         case 124:
         case 125:
         case 126:
            var2[var3] = '_';
         case 48:
         case 49:
         case 50:
         case 51:
         case 52:
         case 53:
         case 54:
         case 55:
         case 56:
         case 57:
         case 65:
         case 66:
         case 67:
         case 68:
         case 69:
         case 70:
         case 71:
         case 72:
         case 73:
         case 74:
         case 75:
         case 76:
         case 77:
         case 78:
         case 79:
         case 80:
         case 81:
         case 82:
         case 83:
         case 84:
         case 85:
         case 86:
         case 87:
         case 88:
         case 89:
         case 90:
         case 95:
         case 97:
         case 98:
         case 99:
         case 100:
         case 101:
         case 102:
         case 103:
         case 104:
         case 105:
         case 106:
         case 107:
         case 108:
         case 109:
         case 110:
         case 111:
         case 112:
         case 113:
         case 114:
         case 115:
         case 116:
         case 117:
         case 118:
         case 119:
         case 120:
         case 121:
         case 122:
         default:
            ++var3;
         }
      }

      return new String(var2);
   }

   String a(int var1) {
      Object var2 = this.h.get(var1);
      return var2 != null ? (String)var2 : this.a.a();
   }

   String b(int var1) {
      Object var2 = this.g.get(var1);
      return var2 != null ? (String)var2 : this.b.b();
   }

   void a(zapt var1) {
      this.a(this.j.getRows());
      this.a(this.j.getColumns());
      this.b();
      this.a();
      this.c();
      this.b(var1);
   }

   void b(zapt var1) {
      int var2;
      int var3;
      if (this.i.getHorizontalPageBreaks() != null && this.i.getHorizontalPageBreaks().getCount() > 0) {
         this.c = new zaqd(this.j, var1.d.size() + 1);
         this.c.a(2);
         com.aspose.cells.b.a.a.ze.a(var1.d, (Object)this.c);
         var2 = this.i.getHorizontalPageBreaks().getCount();
         this.e = new ArrayList();

         for(var3 = 0; var3 < var2; ++var3) {
            HorizontalPageBreak var4 = this.i.getHorizontalPageBreaks().get(var3);
            if (var4 != null) {
               com.aspose.cells.b.a.a.ze.a(this.e, (Object)var4.getRow());
            }
         }
      }

      if (this.i.getVerticalPageBreaks() != null && this.i.getVerticalPageBreaks().getCount() > 0) {
         this.d = new zaps(this.j, var1.c.size() + 1);
         this.d.a(2);
         com.aspose.cells.b.a.a.ze.a(var1.c, (Object)this.d);
         var2 = this.i.getVerticalPageBreaks().getCount();
         this.f = new ArrayList();

         for(var3 = 0; var3 < var2; ++var3) {
            VerticalPageBreak var5 = this.i.getVerticalPageBreaks().get(var3);
            if (var5 != null) {
               com.aspose.cells.b.a.a.ze.a(this.f, (Object)var5.getColumn());
            }
         }
      }

   }

   void a(RowCollection var1) {
      zr var2 = var1.c;
      zahl var3 = var2.a(-1, -1, false);
      zbbj var6 = new zbbj();

      while(true) {
         zp var5;
         boolean var8;
         double var9;
         do {
            int var4 = var3.a();
            if (var4 < 0) {
               return;
            }

            var5 = var2.f(var4);
            zbbj var7 = var5.a(var6, 15);
            var8 = var7.c();
            var9 = (double)var7.e / 20.0D / 72.0D;
         } while(this.a.a(var8, var9));

         boolean var11 = false;

         for(int var12 = this.k.d.size() - 1; var12 > -1; --var12) {
            zaqd var13 = (zaqd)this.k.d.get(var12);
            if (var13.a(var8, var9)) {
               this.h.put(var5.h(), var13.a());
               var11 = true;
               break;
            }
         }

         if (!var11) {
            zaqd var14 = new zaqd(var8, var9);
            com.aspose.cells.b.a.a.ze.a(this.k.d, (Object)var14);
            var14.a("ro" + this.k.d.size());
            this.h.put(var5.h(), var14.a());
         }
      }
   }

   void a(ColumnCollection var1) {
      Iterator var2 = var1.iterator();

      while(true) {
         Column var3;
         do {
            if (!var2.hasNext()) {
               return;
            }

            var3 = (Column)var2.next();
            if (!this.o && var3.e()) {
               this.o = true;
            }
         } while(this.b.a(var3, this.j.getColumnWidthInch(var3.getIndex())));

         boolean var4 = false;

         for(int var5 = 0; var5 < this.k.c.size(); ++var5) {
            zaps var6 = (zaps)this.k.c.get(var5);
            if (var6.a(var3, this.j.getColumnWidthInch(var3.getIndex()))) {
               this.g.put(var3.getIndex(), var6.b());
               var4 = true;
               break;
            }
         }

         if (!var4) {
            zaps var7 = new zaps(var3, this.j.getColumnWidthInch(var3.getIndex()));
            com.aspose.cells.b.a.a.ze.a(this.k.c, (Object)var7);
            var7.a("co" + this.k.c.size());
            this.g.put(var3.getIndex(), var7.b());
         }
      }
   }

   private void b() {
      ArrayList var1 = this.j.getMergedCells();
      this.n = new ArrayList(var1.size());
      WorksheetCollection var2 = this.k.a.getWorksheets();

      for(int var3 = 0; var3 < var1.size(); ++var3) {
         CellArea var4 = (CellArea)var1.get(var3);
         zaqm var5 = new zaqm(var4);
         com.aspose.cells.b.a.a.ze.a(this.n, (Object)var5);
         int var6 = this.j.c(var4.StartRow, var4.StartColumn);
         if (var6 == -1) {
            var6 = 15;
         }

         int var7 = var6;
         if (var4.StartRow != var4.EndRow || var4.StartColumn != var4.EndColumn) {
            var7 = this.j.c(var4.EndRow, var4.EndColumn);
            if (var7 == -1) {
               var7 = 15;
            }
         }

         if (var6 == var7) {
            var5.e = var7;
         } else {
            Style var8 = this.k.a.getWorksheets().f(var6);
            Style var9 = this.k.a.getWorksheets().f(var7);
            if (var8.f()) {
               if (var9.f()) {
                  Style var10 = new Style(var2);
                  var10.copy(var8);
                  var10.getBorders().getByBorderType(2).a(var9.getBorders().getByBorderType(2));
                  var10.getBorders().getByBorderType(8).a(var9.getBorders().getByBorderType(8));
                  var5.e = var2.a(var10);
               } else {
                  var5.e = var6;
               }
            } else if (var9.f()) {
               var5.e = var7;
            }
         }
      }

   }

   private void c() {
      if (this.i.t() != null && this.i.getShapes().getCount() != 0) {
         this.u = new ArrayList();
         int var1 = 0;

         while(var1 < this.i.getShapes().getCount()) {
            Shape var2 = this.i.getShapes().get(var1);
            switch(var2.getMsoDrawingType()) {
            default:
               com.aspose.cells.b.a.a.ze.a(this.u, (Object)(new zaqy(var2)));
            case 25:
               ++var1;
            }
         }

      }
   }

   void a() {
      PageSetup var1 = this.i.getPageSetup();
      String var2 = var1.getHeader(0);
      this.a(var2, 0, "&L");
      var2 = var1.getHeader(1);
      this.a(var2, 1, "&C");
      var2 = var1.getHeader(2);
      this.a(var2, 2, "&R");
      var2 = var1.getFooter(0);
      this.b(var2, 0, "&L");
      var2 = var1.getFooter(1);
      this.b(var2, 1, "&C");
      var2 = var1.getFooter(2);
      this.b(var2, 2, "&R");
      ArrayList var3;
      Font var4;
      if (this.s != null || this.t != null) {
         var3 = this.k.k;
         if (var3.size() == 0) {
            var4 = new Font(this.i.c(), (Object)null, false);
            var4.c(this.i.c().G());
            var4.d(1);
            com.aspose.cells.b.a.a.ze.a(var3, (Object)var4);
         }

         if (this.s != null) {
            this.a(var3, this.s);
         }

         if (this.t != null) {
            this.a(var3, this.t);
         }
      }

      this.p = var1.isHFDiffOddEven();
      if (this.p) {
         var2 = var1.getEvenHeader(0);
         this.c(var2, 0, "&L");
         var2 = var1.getEvenHeader(1);
         this.c(var2, 1, "&C");
         var2 = var1.getEvenHeader(2);
         this.c(var2, 2, "&R");
         var2 = var1.getEvenFooter(0);
         this.d(var2, 0, "&L");
         var2 = var1.getEvenFooter(1);
         this.d(var2, 1, "&C");
         var2 = var1.getEvenFooter(2);
         this.d(var2, 2, "&R");
         if (this.q != null || this.r != null) {
            var3 = this.k.k;
            if (var3.size() == 0) {
               var4 = new Font(this.i.c(), (Object)null, false);
               var4.c(this.i.c().G());
               var4.d(1);
               com.aspose.cells.b.a.a.ze.a(var3, (Object)var4);
            }

            if (this.q != null) {
               this.a(var3, this.q);
            }

            if (this.r != null) {
               this.a(var3, this.r);
            }
         }
      }

   }

   private void a(ArrayList var1, ArrayList[] var2) {
      for(int var3 = 0; var3 < var2.length; ++var3) {
         ArrayList var4 = var2[var3];
         if (var4 != null) {
            for(int var5 = 0; var5 < var4.size(); ++var5) {
               HeaderFooterCommand var6 = (HeaderFooterCommand)var4.get(var5);
               if (var6.getFont() != null) {
                  boolean var7 = false;

                  for(int var8 = 0; var8 < var1.size(); ++var8) {
                     Font var9 = (Font)var1.get(var8);
                     if (var9.equals(var6.getFont())) {
                        var6.getFont().d(var8 + 1);
                        var7 = true;
                        break;
                     }
                  }

                  if (!var7) {
                     com.aspose.cells.b.a.a.ze.a(var1, (Object)var6.getFont());
                     var6.getFont().d(var1.size());
                  }
               }
            }
         }
      }

   }

   private void a(String var1, int var2, String var3) {
      if (var1 != null && !"".equals(var1)) {
         if (var1.startsWith(var3)) {
            var1 = var1.substring(2);
         }

         ArrayList var4 = HeaderFooterCommand.a(this.i.getWorkbook(), var1);
         if (var4 != null && var4.size() != 0) {
            if (this.s == null) {
               this.s = new ArrayList[3];
            }

            this.s[var2] = var4;
         }
      }

   }

   private void b(String var1, int var2, String var3) {
      if (var1 != null && !"".equals(var1)) {
         if (var1.startsWith(var3)) {
            var1 = var1.substring(2);
         }

         ArrayList var4 = HeaderFooterCommand.a(this.i.getWorkbook(), var1);
         if (var4 != null && var4.size() != 0) {
            if (this.t == null) {
               this.t = new ArrayList[3];
            }

            this.t[var2] = var4;
         }
      }

   }

   private void c(String var1, int var2, String var3) {
      if (var1 != null && !"".equals(var1)) {
         if (var1.startsWith(var3)) {
            var1 = var1.substring(2);
         }

         ArrayList var4 = HeaderFooterCommand.a(this.i.getWorkbook(), var1);
         if (var4 != null && var4.size() != 0) {
            if (this.q == null) {
               this.q = new ArrayList[3];
            }

            this.q[var2] = var4;
         }
      }

   }

   private void d(String var1, int var2, String var3) {
      if (var1 != null && !"".equals(var1)) {
         if (var1.startsWith(var3)) {
            var1 = var1.substring(2);
         }

         ArrayList var4 = HeaderFooterCommand.a(this.i.getWorkbook(), var1);
         if (var4 != null && var4.size() != 0) {
            if (this.r == null) {
               this.r = new ArrayList[3];
            }

            this.r[var2] = var4;
         }
      }

   }

   Comment a(int var1, int var2) {
      if (this.i.t() != null && this.i.getShapes().getCount() != 0) {
         for(int var3 = 0; var3 < this.i.getComments().getCount(); ++var3) {
            Comment var4 = this.i.getComments().get(var3);
            if (var4.getRow() == var1 && var4.getColumn() == var2) {
               return var4;
            }
         }

         return null;
      } else {
         return null;
      }
   }

   ArrayList b(int var1, int var2) {
      if (this.u != null && this.u.size() != 0) {
         ArrayList var3 = new ArrayList();

         for(int var4 = 0; var4 < this.u.size(); ++var4) {
            zaqy var5 = (zaqy)this.u.get(var4);
            if (var5.f == var1 && var5.g == var2) {
               com.aspose.cells.b.a.a.ze.a(var3, (Object)var5);
               this.u.remove(var4--);
            }
         }

         if (var3.size() == 0) {
            return null;
         } else {
            return var3;
         }
      } else {
         return null;
      }
   }

   zaqm c(int var1, int var2) {
      for(int var3 = 0; var3 < this.n.size(); ++var3) {
         zaqm var4 = (zaqm)this.n.get(var3);
         if (var4.b < var1) {
            this.n.remove(var3--);
         } else if (var1 >= var4.a && var1 <= var4.b && var2 >= var4.c && var2 <= var4.d) {
            return var4;
         }
      }

      return null;
   }
}
